package com.gym.code.generator.utils;

import java.io.File;
import java.util.List;

import org.apache.commons.collections.CollectionUtils;

import com.gym.code.generator.Contants;

/**
 * 
 * @author xinchun.wang
 * @email: 532002108@qq.com
 * @createTime 2015-4-12 上午10:23:15
 */
public abstract class GenerateFileUtils {
	public static String[] getFilePathAndName(String packagePath) {
		int index = packagePath.lastIndexOf(File.separator);
		String fileDir = packagePath.substring(0, index);
		String fileName = packagePath.substring(index + 1);
		return new String[] { fileDir, fileName };
	}

	public static String generateWithSpace(List<String> list) {
		StringBuilder builder = new StringBuilder();
		if (CollectionUtils.isEmpty(list)) {
			return builder.toString();
		}
		for (int i = 0; i < list.size(); i++) {
			String item = list.get(i);
			builder.append(item);
			if (!(Contants.$tab.equals(item) || Contants.$space.equals(item))) {
				if (i != list.size() - 1) {
					builder.append(" ");
				}
			}
		}
		return builder.toString();
	}

	public static String generateChar(int times, String c) {
		StringBuilder builder = new StringBuilder();
		for (int i = 0; i < times; i++) {
			builder.append(c);
		}
		return builder.toString();
	}
}
